def sumOfSquareOfDigits(number)
	sumOfSquareOfDigits = 0
	number.to_s.scan(/./).each do |digit|
		sumOfSquareOfDigits = sumOfSquareOfDigits + (digit.to_i(10) ** 2)
	end
	sumOfSquareOfDigits
end

numbers = []
(1..10000000).each do |number|
	originalNumber = number
	while number != 1 and number != 89
		number = sumOfSquareOfDigits number
	end

	if number == 89
		numbers.push originalNumber
	end
end

puts numbers.length